package com.example.himalayaproject.subscription.fragment;


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.himalayaproject.R;
import com.example.himalayaproject.subscription.adapter.SubRecommendAdapter;
import com.example.himalayaproject.subscription.bean.recommendentity.LikeEntity;
import com.example.himalayaproject.subscription.callback.HttpSercive;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * A simple {@link Fragment} subclass.
 */
public class SubRecommendFragment extends Fragment implements Callback<LikeEntity> {
    private RecyclerView recycle;
    private SubRecommendAdapter adapter;
    public SubRecommendFragment() {

    }
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_sub_recommend, container, false);
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
       aboutRecyclerView(view);
    }

    private void aboutRecyclerView(View view) {
        HttpSercive sercive = new Retrofit.Builder()
                .baseUrl("http://mobile.ximalaya.com/")
                .addConverterFactory(GsonConverterFactory.create())
                .build()
                .create(HttpSercive.class);
        sercive.getList().enqueue(this);
        recycle = ((RecyclerView) view.findViewById(R.id.sub_recommend_recycle));
        adapter =  new SubRecommendAdapter(getContext());
        recycle.setAdapter(adapter);

    }

    @Override
    public void onResponse(Call<LikeEntity> call, Response<LikeEntity> response) {
         adapter.addAll(response.body().getGuess().getList());
    }

    @Override
    public void onFailure(Call<LikeEntity> call, Throwable t) {

    }
}
